package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.bo.ParttimeDayBo;
import com.groupseven.happycampus.common.bo.ParttimeHolidayBo;
import com.groupseven.happycampus.common.pojo.ParttimeHoliday;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.mapper.ParttimeHolidayMapper;
import com.groupseven.happycampus.service.ParttimeHolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @CreateTime: 2022-07-26  21:47
 */
@Service("/parttimeHolidayService")
public class ParttimeHolidayServiceImpl implements ParttimeHolidayService {

    @Autowired
    private ParttimeHolidayMapper parttimeHolidayMapper;


    @Override
    public List<ParttimeHoliday> parttimeHolidayList() {
        return parttimeHolidayMapper.findAllParttimeHolidays(null);
    }

    @Override
    public LayuiPageVo<ParttimeHoliday> parttimeHolidayPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);


        List<ParttimeHoliday> parttimeHolidays = parttimeHolidayMapper.selectParttimeHolidayByParams(params);

        PageInfo<ParttimeHoliday> parttimeHolidayPageInfo = new PageInfo<>(parttimeHolidays);

        LayuiPageVo<ParttimeHoliday> parttimeHolidayLayuiPageVo = new LayuiPageVo<>();

        parttimeHolidayLayuiPageVo.setCode(0);
        parttimeHolidayLayuiPageVo.setMsg("分页类表数据");
        parttimeHolidayLayuiPageVo.setCount(parttimeHolidayPageInfo.getTotal());
        parttimeHolidayLayuiPageVo.setData(parttimeHolidayPageInfo.getList());

        return parttimeHolidayLayuiPageVo;
    }

    @Override
    public int deleteParttimeHoliday(Integer id) {
        return parttimeHolidayMapper.deleteParttimeHoliday(id);
    }

    @Override
    public int deleteParttimeHolidayByIds(String ids) {
        String[] arrId = ids.split(",");
        return parttimeHolidayMapper.deleteParttimeHolidayByIds(arrId);
    }

    @Override
    public int updateParttimeHoliday(ParttimeHoliday parttimeHoliday) {
        return parttimeHolidayMapper.updateParttimeHoliday(parttimeHoliday);
    }

    @Override
    public int insertParttimeHoliday(ParttimeHoliday parttimeHoliday) {
        return parttimeHolidayMapper.insertParttimeHoliday(parttimeHoliday);
    }

    @Override
    public List<ParttimeHolidayBo> parttimeHolidayExcelData(ParttimeHoliday parttimeHoliday) {
        List<ParttimeHoliday> parttimeHolidays = parttimeHolidayMapper.selectParttimeHolidays(parttimeHoliday);

        List<ParttimeHolidayBo> parttimeHolidayBos = parttimeHolidays.stream().map((p) -> {
            ParttimeHolidayBo parttimeHolidayBo = new ParttimeHolidayBo();
            parttimeHolidayBo.setId(p.getId());
            parttimeHolidayBo.setPosition(p.getPosition());
            parttimeHolidayBo.setCompany(p.getCompany());
            parttimeHolidayBo.setWage(p.getWage());
            parttimeHolidayBo.setTelephone(p.getTelephone());
            parttimeHolidayBo.setRegion(p.getRegion());
            parttimeHolidayBo.setDescription(p.getDescription());
            return parttimeHolidayBo;
        }).collect(Collectors.toList());

        return parttimeHolidayBos;

    }

}
